<?php
class Compress_Task
{

    public function run()
    {

        $start = time();
        $this->compress_js(Asset::container()->assets['script']);
        $this->compress_css(Asset::container()->assets['style']);

        echo "\nCompleted in " . (time() - $start);
    }

    private function compress_js($scripts)
    {
        $compiled = '';
        $output = path('public') . Config::get('compressor.output.js');
        foreach ($scripts as $script) {
            $file = path('public') . $script['source'];
            $compiled .= file_get_contents($file) . "\n";
        }

        file_put_contents($output, JSMinPlus::minify($compiled));

    }

    protected static function compress_css($styles)
    {
        $compiled = '';
        $output = path('public') . Config::get('compressor.output.css');

        foreach ($styles as $style) {
            $file = path('public') . $style['source'];
            $compiled .= file_get_contents($file) . "\n";
        }

        $engineer = new CSSmin(true);
        file_put_contents($output, $engineer->run($compiled));
    }
}